home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
-
- AWK_FILE="/tmp/ref.tmp.awk"
-
- trap "/bin/rm -r -f $AWK_FILE" 0 1 2 3 15
-
- #{{{}}}
- #{{{ -d -> gen dependencies
- if test x$1 = x-d
- then
- shift
- AWK=$1
- shift
- #{{{ gen awk script
- cat >$AWK_FILE <<\HERE
- BEGIN {
- fr="\nFUNREF="
- }
- /^ *@if-using *\( *FUN-REFERENCE *\)/ {
- if (u[FILENAME]==0) {
- u[FILENAME]=1;
- fr=fr"\\\n "FILENAME".r";
- d=d"\n"FILENAME".r: "FILENAME;
- }
- }
- END {
- print fr;
- print d;
- }
- HERE
- #}}}
- ( echo "# automatically generated dependency file"
- $AWK -f $AWK_FILE $@
- ) >dependencies
- exit 0
- fi
- #}}}
- #{{{ -r -> gen references
- if test x$1 = x-r
- then
- shift
- AWK=$1
- shift
- #{{{ gen awk script
- cat >$AWK_FILE <<\HERE
- #{{{ init: not text written, no chapters seen, predefined chapter names
- BEGIN {
- if_depth=0
- chapters=0
- handle=""
- chap_name["1"]="Description"
- chap_name["2"]="Functions and macros"
- chap_name["3"]="Hooks"
- chap_name["4"]="Libraries"
- chap_name["5"]="Bugs and limitations"
- libs=""
- }
- #}}}
- #{{{ set filename
- name=="" {
- name=FILENAME
- for (i=1;i<=length(name);)
- if (substr(name,i,1)=="/") {
- name=substr(name,i+1)
- i=1
- } else
- i=i+1
- }
- #}}}
- #{{{ store lib
- /^ *@lib +[^ ]*$/ {
- if (lib_used[$2]==0) {
- lib_used[$2]=1
- if (libs=="")
- libs=" The library '"name"' uses the libraries:\n"
- libs=libs" '"$2"'\n"
- }
- }
- #}}}
- #{{{ start pattern found, set handling to TRUE, store destination chapter
- /^ *@if-using +\( +FUN-REFERENCE +\) +;( +[^ ]+)+ +;( +[^ ]+)* *$/ {
- # {{{ get chapter name
- handle=$6
- for (i=7;i<=NF && $i!=";";i++)
- handle=handle" "$i
- if (chap_name[handle]=="")
- chap_name[handle]=handle
- else
- handle=chap_name[handle]
- if (defined[handle]=="") {
- defined[handle]="@"
- tags[handle]=" complete"
- chapter[chapters++]=handle
- }
- # }}}
- # {{{ get if-using tags for this entry
- text[handle]=text[handle]"@if-using ( complete"
- for (i++;i<=NF;i++) {
- tags[handle]=tags[handle]" "$i
- text[handle]=text[handle]" "$i
- }
- text[handle]=text[handle]" )\n"
- # }}}
- # {{{ get indentation
- skip_txt=""
- skip_len=0
- while(substr($0,skip_len+1,1)==" ") {
- skip_len++
- skip_txt=skip_txt" "
- }
- # }}}
- if_depth=1
- next
- }
- #}}}
- #{{{ handling FALSE -> next
- if_depth==0 {
- next
- }
- #}}}
- #{{{ handle depth of if-usings, maybe end handling
- /^ *@ *if-using/ {
- if_depth++
- }
- /^ *@ *fi/ {
- if_depth--
- }
- if_depth==0 {
- text[handle]=text[handle]"@fi\n"
- handle=""
- next
- }
- handle=="" {
- next
- }
- #}}}
- #{{{ check indentation of reference line
- $0!="" && skip_txt!=substr($0,1,skip_len) {
- print("@error incorrect indentation of reference-source (need indentation "skip_len"!")
- exit
- }
- #}}}
- #{{{ store text to wished chapter
- /^ *;OCL\{\{\{ @/ {
- text[handle]=text[handle]"@{{{ "substr($0,10+skip_len)"\n"
- next
- }
- /^ *;OCL\{\{\{/ {
- text[handle]=text[handle]"@{{{ @"name"-ref "substr($0,10+skip_len)"\n"
- next
- }
- /^ *;OCL\}\}\}/ {
- text[handle]=text[handle]"@"substr($0,5+skip_len)"\n"
- next
- }
- { text[handle]=text[handle] substr($0,skip_len+1)"\n"
- next
- }
- #}}}
- #{{{ end: print all stored text/chapters
- END {
- if (libs!="" && defined[chap_name[4]]=="") {
- tags[chap_name[4]]=" complete"
- chapter[chapters++]=chap_name[4]
- text[chap_name[4]]=libs
- }
- print("@ref-see-also See also in %s.")
- print("@{{{}}}");
- print("@{{{ "name"-reference-file")
- for (i=0;i<chapters;i++) {
- if (tags[chapter[i]]!="")
- print("@if-using ("tags[chapter[i]]" )")
- print("@{{{ @"name"-ref "chapter[i])
- printf("%s",text[chapter[i]])
- print("@}}}")
- if (tags[chapter[i]]!="")
- print("@fi")
- }
- print("@}}}")
- }
- #}}}
- HERE
- #}}}
- $AWK -f $AWK_FILE $@
- exit 0
- fi
- #}}}
- #{{{ show help
- echo "USAGE:"
- echo " fun2ref -[dr] awk files"
- echo "where:"
- echo " -d generates dependencies"
- echo " -r extracts the reference data from library files"
- #}}}
-